package com.jason.quectel.activities;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.widget.ImageView;

import com.jason.quectel.R;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;

public class AnimationTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation_test);

        ImageView imageView = findViewById(R.id.imageView_animation);

        //逐帧动画
        //imageView.setImageResource(R.drawable.frame);
        //AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable();
        //animationDrawable.start();

        //补间动画
        //Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_clockwise);
        //animation.setRepeatMode(Animation.RESTART);
        //animation.setRepeatCount(Animation.INFINITE);
        //imageView.startAnimation(animation);

        //属性动画
        //ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 100).setDuration(1000);
        //valueAnimator.addListener(new Animator.AnimatorListener() {
        //    @Override
        //    public void onAnimationStart(Animator animation, boolean isReverse) {
        //        Animator.AnimatorListener.super.onAnimationStart(animation, isReverse);
        //    }
        //
        //    @Override
        //    public void onAnimationEnd(Animator animation, boolean isReverse) {
        //        Animator.AnimatorListener.super.onAnimationEnd(animation, isReverse);
        //    }
        //
        //    @Override
        //    public void onAnimationStart(Animator animation) {
        //
        //    }
        //
        //    @Override
        //    public void onAnimationEnd(Animator animation) {
        //
        //    }
        //
        //    @Override
        //    public void onAnimationCancel(Animator animation) {
        //
        //    }
        //
        //    @Override
        //    public void onAnimationRepeat(Animator animation) {
        //
        //    }
        //});
        //valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        //    @Override
        //    public void onAnimationUpdate(ValueAnimator animation) {
        //
        //    }
        //});
        //valueAnimator.start();

        ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(imageView, "scaleX", 0, 2);
        ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(imageView, "scaleY", 0, 2);
        ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(imageView, "rotation", 0, 360);
        ObjectAnimator objectAnimator4 = ObjectAnimator.ofFloat(imageView, "translationX", 0, 100);
        ObjectAnimator objectAnimator5 = ObjectAnimator.ofFloat(imageView, "translationY", 0, 100);
        ObjectAnimator objectAnimator6 = ObjectAnimator.ofFloat(imageView, "alpha", 1, 0);
        List<Animator> list = new ArrayList<>();
        list.add(objectAnimator1);
        list.add(objectAnimator2);
        list.add(objectAnimator3);
        list.add(objectAnimator4);
        list.add(objectAnimator5);
        list.add(objectAnimator6);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playSequentially(list);
        animatorSet.setDuration(1000);
        animatorSet.start();

        //objectAnimator.setDuration(1000);
        //objectAnimator.setRepeatCount(ValueAnimator.INFINITE);
        //objectAnimator.setRepeatMode(ValueAnimator.RESTART);
        //objectAnimator.start();

    }
}